package edu.fdzc.learn.service.impl;

import edu.fdzc.learn.entity.CouStu;
import edu.fdzc.learn.entity.User;
import edu.fdzc.learn.mapper.CouStuMapper;
import edu.fdzc.learn.mapper.UserMapper;
import edu.fdzc.learn.service.CouStuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CouStuServiceImpl implements CouStuService {

    @Autowired
    private CouStuMapper couStuMapper;

    @Autowired
    private UserMapper userMapper;

    @Override
    public void insert(int courseId, int stuId) {

        User user = userMapper.findById(stuId);
        if(user != null){
            couStuMapper.insert(courseId,stuId);
        }

    }

    @Override
    public void inserts(int courseId, int[] stuIds) {
        for(int ids : stuIds){
            User user = userMapper.findById(ids);
            if(user != null){
                couStuMapper.insert(courseId,ids);
            }
        }
    }

    @Override
    public void delete(int courseId, int stuId) {
        CouStu couStu = couStuMapper.findBySId(courseId,stuId);
        if(couStu != null){
            couStuMapper.delete(courseId,stuId);
        }
    }

    @Override
    public void deletes(int courseId, int[] stuIds) {
        for (int id : stuIds) {
            delete(courseId, id);
        }
    }
}
